using MicroMsg.Common.Utils;
using System;
namespace MicroMsg.UI.Util
{
	public class SearchKeyExInfo
	{
		public string mStrKeyExInfo;
		public int[] mAIndexs;
		private SearchType mSearchType;
		public SearchMatchRange Match(ref string content)
		{
			if (string.IsNullOrEmpty(content))
			{
				return null;
			}
			int num = this.mStrKeyExInfo.IndexOf(content);
			int num2 = num + content.get_Length() - 1;
			if (-1 == num)
			{
				return null;
			}
			if (this.mSearchType != SearchType.Pinyin)
			{
				return new SearchMatchRange(num, num2);
			}
			if (this.mAIndexs == null)
			{
				return null;
			}
			bool flag = false;
			bool flag2 = false;
			for (int i = 0; i < this.mAIndexs.Length; i++)
			{
				if (!flag && (this.mAIndexs[i] > num || this.mAIndexs[i] > num2))
				{
					return null;
				}
				if (this.mAIndexs[i] == num)
				{
					if (flag)
					{
						return null;
					}
					flag = true;
					num = i;
				}
				if (flag && this.mAIndexs[i] > num2)
				{
					flag2 = true;
					num2 = i - 1;
				}
				if (this.mAIndexs[i] == num2)
				{
					if (!flag)
					{
						return null;
					}
					flag2 = true;
					num2 = i;
				}
				if (flag && i == this.mAIndexs.Length - 1 && this.mAIndexs[i] < num2)
				{
					flag2 = true;
					num2 = i;
				}
				if (flag && flag2)
				{
					return new SearchMatchRange(num, num2);
				}
			}
			return null;
		}
		public static SearchKeyExInfo MakeSearchKeyExInfo(ref string strKey, SearchType searchType)
		{
			if (string.IsNullOrEmpty(strKey))
			{
				return null;
			}
			switch (searchType)
			{
			case SearchType.OriginContent:
				return new SearchKeyExInfo
				{
					mSearchType = searchType,
					mStrKeyExInfo = strKey
				};
			case SearchType.Pinyin:
			{
				SearchKeyExInfo searchKeyExInfo = new SearchKeyExInfo();
				searchKeyExInfo.mSearchType = searchType;
				searchKeyExInfo.mAIndexs = new int[strKey.get_Length()];
				int[] arg_74_0 = searchKeyExInfo.mAIndexs;
				int expr_6F = 0;
				int num = expr_6F + 1;
				arg_74_0[expr_6F] = 0;
				string text = strKey;
				for (int i = 0; i < text.get_Length(); i++)
				{
					char char_ = text.get_Chars(i);
					SearchKeyExInfo expr_86 = searchKeyExInfo;
					expr_86.mStrKeyExInfo += GetPinYin.ConvertStrToQuanPin(char_);
					if (num <= strKey.get_Length() - 1)
					{
						searchKeyExInfo.mAIndexs[num++] = searchKeyExInfo.mStrKeyExInfo.get_Length();
					}
				}
				return searchKeyExInfo;
			}
			case SearchType.FirstPinyin:
				return new SearchKeyExInfo
				{
					mSearchType = searchType,
					mStrKeyExInfo = SortStringsByAlpha.GetFirstPinyinLower(strKey)
				};
			}
			return null;
		}
	}
}
